﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    CustomerBus cusBus = new CustomerBus();

    protected void Page_Load(object sender, EventArgs e)
    {
        checkUserLife();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string email = Convert.ToString(Session["username"]);
        string passnew = txtPassNew.Text;
        string passConfirm = txtPassConfirm.Text;
        string passold = txtPassOld.Text;
        if (passConfirm != passnew) 
        {
            ScriptManager.RegisterStartupScript(this, typeof(Page), "Muabanct.com", "<script>alert('Hai mật khẩu phải giống nhau')</script>", false);
            txtPassConfirm.Text = "";
            txtPassConfirm.Focus();
        }
        else 
        {
            if (cusBus.ChangePass(email, passold, passnew))
            {
                ScriptManager.RegisterStartupScript(this, typeof(Page), "Muabanct.com", "<script>alert('Đổi mật khẩu thành công')</script>", false);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, typeof(Page), "Muabanct.com", "<script>alert('Mật khẩu cũ không đúng')</script>", false);
                txtPassOld.Focus();
            }
        }

    }
    public void checkUserLife()
    {
        if (Session["username"] == "" || Session["username"] == null)
        {
            Response.Redirect("default.aspx");
        }
    }
}